package com.zhejiangzhengyuan.municipal_common.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhejiangzhengyuan.municipal_common.entity.Permission;
import com.zhejiangzhengyuan.municipal_common.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhejiangzhengyuan.municipal_common.entity.vo.RoleVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * 角色表 Mapper 接口
 * </p>
 *
 * @author linju
 * @since 2019-11-22
 */
@Repository
public interface RoleMapper extends BaseMapper<Role> {


    @Select("select p.* from role r,permission p,role_permission_mapping rpm \n" +
            "            where r.id=rpm.role_id and p.id = rpm.permission_id and r.id=#{rid}")
    List<Permission> selectRoleByPermission(@Param("rid") Long id);

    @Select("select r.role_name from subject s,role r,subject_role_mapping srm,user_info u,subject_user_info_mapping sum\n" +
            "            where u.id=sum.user_info_id and sum.subject_id=s.id and srm.subject_id =s.id and srm.role_id=r.id and u.id=#{uid}")
    List<String> selectRoleNameListByUserId(@Param("uid") Long id);

    @Select("select id,role_name from role")
    List<RoleVo> RoleVo();


    @Select("select * from role r")
    Page<RoleVo> selectRoleVo(Page<RoleVo> page);
}
